<!--
 * @Author: hucc
 * @Date: 2021-09-29 11:26:12
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-06 17:49:44
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.js"></script>
</head>

<body>
    <!-- generator 异步编程解决方案 -->
    <!-- async 底层实现方法是generator 迭代器对象 -->
    <!-- async是generator的语法糖 -->
</body>
<script>
    function* test() {
        let res = yield getAjax();

        //上一状态的结果作为下一状态的入口
        console.log(res);
        yield '状态二'

        yield '状态三'
    }
    let result = test();
    console.log(result); //Generator {  }
    console.log(result.next());

    function getAjax() {
        $.ajax({
            url: "http://39.103.202.53:8888/index/category/findAll",
            method: 'get',
            success: function(res) {
                result.next(res);
            }
        })
    }
</script>

</html>